package mww.servlet.course;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import mww.common.DaoException;
import mww.common.ServiceException;
import mww.javabean.entity.Course;
import mww.javabean.service.CourseService;
import mww.javabean.service.CourseServiceImpl;
public class UpdateCourseServlet extends HttpServlet {
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		CourseService service = new CourseServiceImpl();
		HttpSession session=request.getSession();
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String courseNo=request.getParameter("courseNo");
		String courseName=request.getParameter("courseName");
		Integer studyTime=new Integer(request.getParameter("studyTime"));
		Float credit=new Float(request.getParameter("credit"));
		Integer courseType=new Integer(request.getParameter("courseType"));
		Integer term=new Integer(request.getParameter("term"));
		try{
	  		Course course=service.findCourseByCourseNo(courseNo);
	  		course.setCourseNo(courseNo);
	  		course.setCourseName(courseName);
	  		course.setStudyTime(studyTime);
	  		course.setCredit(credit);
	  		course.setCourseType(courseType);
	  		course.setTerm(term);
	  		service.updateCourse(course);
	  		session.setAttribute("message", "修改课程信息成功！");
	  		request.getRequestDispatcher("/admin/listAllCourseServlet").forward(request, response);
		}catch (ServiceException e) {
			e.printStackTrace();
			request.setAttribute("se", e);
			request.getRequestDispatcher("/serviceException.jsp").forward(request, response);
		} catch (DaoException e) {
			e.printStackTrace();
			request.setAttribute("de", e);
			request.getRequestDispatcher("/daoException.jsp").forward(request, response);
		}
	}
}
